package bch.redis_search.config;

import jakarta.annotation.Resource;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.redisson.config.ReadMode;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class RedissonConfig {

    @Resource
    RedisProperties redisProperties;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config
                .setCodec(new JsonJacksonCodec())
                .useSentinelServers()
                .setDatabase(0)
                .setReadMode(ReadMode.SLAVE)
                .setMasterName("mymaster")
                .setPassword("Aa123456")
                // 必须保证quorum个sentinel节点可用,否则failover不生效
                // 对于高可用性系统，通常建议至少部署 5 个 Sentinel，以容忍 2 个节点的故障
                .addSentinelAddress("redis://localhost:26379", "redis://localhost:26380", "redis://localhost:26381");
        return Redisson.create(config);
    }

}
